<template>
  <a-layout id="components-layout-demo-custom-trigger" class="globalOuter">
    <!-- 侧边栏 -->
    <a-layout-sider v-model="collapsed" :trigger="null" collapsible>
      <div class="logo outerLogo">
        <!-- Logo图片 -->
        <img src="../assets/img/logo-title.png" class="logoImg" />
      </div>
      <a-menu theme="dark" mode="inline" :default-selected-keys="['2']">
        <!-- 侧边按钮 -->
<!--        <a-menu-item key="1" @click="openJDY()" >-->
<!--          <a-icon type="compass" />-->
<!--          <span>进入主系统</span>-->
<!--        </a-menu-item>-->
        <a-menu-item key="2" @click="goTo('/user/tree')">
          <a-icon type="layout" />
          <span>{{ this.global.bomName }}管理</span>
        </a-menu-item>
<!--        <a-menu-item key="3" @click="goTo('/user/test')" >-->
<!--          <a-icon type="control" />-->
<!--          <span>测试</span>-->
<!--        </a-menu-item>-->
      </a-menu>
    </a-layout-sider>
    <a-layout>

      <!-- 标题栏 -->
      <a-layout-header style="background: #fff; padding: 0">
        <a-icon class="trigger"
                :type="collapsed ? 'menu-unfold' : 'menu-fold'"
                @click="() => (collapsed = !collapsed)" />
        <div class="header-text">JDY-SOLUTION {{this.global.brandName}} 简道云插件</div>
        <a-icon class="trigger outerExit" type="logout" @click="logout()" />
      </a-layout-header>
      <a-layout-content :style="{padding: '24px', minHeight: '280px' }">
        <!-- 页面内容 -->
        <router-view />
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>
<script>

export default {
  data() {
    return {
      collapsed: true,
    };
  },
  mounted: function () {
    this.goTo('/user/tree');
  },
  methods: {
    logout() { // 退出登录y
      localStorage.setItem("login_state", JSON.stringify(0));
      localStorage.setItem("token", ""); // 更新token到本地
      this.$router.push({path: "/login"}); // 跳转到登录
    },
    // API测试模板
    checkToken() {
      let _this = this;
      let axios = require('axios');
      let url = this.global.serverLocation + "/checktoken";
      let login_token = localStorage.getItem("token");
      let data = JSON.stringify({
        "token": login_token,
      });
      let config = {
        method: 'post',
        url: url,
        headers: {
          'Content-Type': 'application/json',
        },
        data: data
      };
      axios(config) // API结果
          .then(function (response) { // API顺利传回
            console.log(JSON.stringify(response.data));
          })
          .catch(function (error) { // API错误
            console.log(JSON.stringify(error));
          });
    }
  }
};
</script>
<style>
  #components-layout-demo-custom-trigger .trigger {
    font-size: 18px;
    line-height: 64px;
    padding: 0 24px;
    cursor: pointer;
    transition: color 0.3s;
  }

  #components-layout-demo-custom-trigger .trigger:hover {
    color: #1890ff;
  }

  #components-layout-demo-custom-trigger .logo {
    height: 32px;
    background: rgba(255, 255, 255, 0.2);
    margin: 16px;
  }
</style>
